package com.qf.controller;

import com.qf.entity.Hotal;
import com.qf.entity.ResultData;
import com.qf.service.IHotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 微服务间内部调用的接口
 */
@RestController
@RequestMapping("/hotal")
public class HotalController {

    @Autowired
    private IHotalService hotalService;

    /**
     * 新增酒店
     * @param hotal
     * @return
     */
    @RequestMapping("/insert")
    public int insertHotal(@RequestBody Hotal hotal){
        return hotalService.saveHotal(hotal);
    }

    /**
     * 查询酒店列表
     * @return
     */
    @RequestMapping("/list")
    public List<Hotal> queryAll(){
        return hotalService.list();
    }

    /**
     * 根据酒店id查询酒店的详细信息
     * @return
     */
    @RequestMapping("/info")
    public ResultData<Hotal> queryHotal(Integer hid){
        //除了查询酒店信息之外，相当于进行了一次点击
        Hotal hotal = hotalService.getById(hid);
        return new ResultData<Hotal>().setCode(ResultData.Code.CODE_SUCC).setData(hotal);
    }
}
